package com.example.demo.dto;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class Message {
    private boolean state=false;
    private int code;
    private Serializable data;
    private String msg;
    private long time;
    private Collection<Serializable> list;
    private List<Error> errors = new ArrayList<Error>();
    public Message() {
        this.time = System.currentTimeMillis();
    }

    public Message(boolean state, int code, Serializable data, String msg, long time, Collection<Serializable> list) {
        this.state = state;
        this.code = code;
        this.data = data;
        this.msg = msg;
        this.time = time;
        this.list = list;
    }

    public void addError(String attrName, String attrMsg) {
        Error error = new Error();
        error.setErrMsg(attrMsg);
        error.setErrName(attrName);
        this.errors.add(error);
    }

    public boolean isState() {
        return state;
    }

    public void setState(boolean state) {
        this.state = state;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public Serializable getData() {
        return data;
    }

    public void setData(Serializable data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Long getTime() {
        return time;
    }

    public void setTime(Long time) {
        this.time = time;
    }

    public void setTime(long time) {
        this.time = time;
    }

    public Collection<Serializable> getList() {
        return list;
    }

    public void setList(Collection<Serializable> list) {
        this.list = list;
    }

    public List<Error> getErrors() {
        return errors;
    }

    public void setErrors(List<Error> errors) {
        this.errors = errors;
    }

    @Override
    public String toString() {
        return "Message{" +
                "state=" + state +
                ", code=" + code +
                ", data=" + data +
                ", msg='" + msg + '\'' +
                ", time=" + time +
                ", list=" + list +
                ", errors=" + errors +
                '}';
    }
}

class Error {
    private String errMsg;
    private String errName;

    public Error() {
    }

    @Override
    public String toString() {
        return "Error{" +
                "errMsg='" + errMsg + '\'' +
                ", errName='" + errName + '\'' +
                '}';
    }

    public String getErrMsg() {
        return errMsg;
    }

    public void setErrMsg(String errMsg) {
        this.errMsg = errMsg;
    }

    public String getErrName() {
        return errName;
    }

    public void setErrName(String errName) {
        this.errName = errName;
    }
}
